package InterviewTest.q0402_sortedArrayToBST;

import CommonClass.Common.TreeNode;

public class Solution {
    /*
    直接使用dfs
    注意边界即可
     */
    public TreeNode sortedArrayToBST(int[] nums) {
        return dfs(nums, 0, nums.length);
    }

    private TreeNode dfs(int[] nums, int start, int end) {
        if (start >= end) return null;
        int mid = start + ((end - start) >> 1);
        TreeNode root = new TreeNode(nums[mid]);
        root.left = dfs(nums, start, mid);
        root.right = dfs(nums, mid + 1, end);
        return root;
    }
}
